package com.example.springboot.config.cors;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/9/8 14:48
 */
@RestController
@RequestMapping("/cors")
public class ResponseController {
    @GetMapping("/test123")
    public HashMap<String, String> demo(HttpServletResponse response) {
        // 通过设置响应头来设置跨域
        // 局部跨域
        response.setHeader("Access-Control-Allow-Origin", "*");
        return new HashMap<String, String>() {
            {
                put("a", "a");
                put("c", "c");
            }
        };
    }
}
